<?php
namespace Home\Model;
use Think\Model;
class EmailModel extends Model {
	public $api_user = 'postmaster@xueyanshe.sendcloud.org';
	public $api_key = 'LztTYv92';
	public function send($to, $subject, $html, $fromname = '枫桥居', $from = 'admin@fengqiaoju.com') {
		$url = 'https://sendcloud.sohu.com/webapi/mail.send.json';
		$param = array (
				'api_user' => C('sendcloud_api_user'),
				'api_key' => C('sendcloud_api_key'),
				'from' => $from,
				'fromname' => $fromname,
				'to' => $to,
				'subject' => $subject,
				'html' => $html
		);
		$result = $this->_request ( $url, $param );
		return $result;
	}
	private function _request($url, $param) {
		$options = array (
				'http' => array (
						'method' => 'POST',
						'content' => http_build_query ( $param )
				)
		);
		$context = stream_context_create ( $options );
		$result = file_get_contents ( $url, false, $context );

		return $result;
	}
}